
package net.sf.odinms.client.messages.commands;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ScheduledFuture;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

import net.sf.odinms.client.Equip;
import net.sf.odinms.client.IItem;
import net.sf.odinms.client.ISkill;
import net.sf.odinms.client.Item;
import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleClient;
import net.sf.odinms.client.MapleInventoryType;
import net.sf.odinms.client.MapleJob;
import net.sf.odinms.client.MaplePet;
import net.sf.odinms.client.MapleStat;
import net.sf.odinms.client.SkillFactory;
import net.sf.odinms.client.messages.Command;
import net.sf.odinms.client.messages.CommandDefinition;
import static net.sf.odinms.client.messages.CommandProcessor.getOptionalIntArg;
import net.sf.odinms.client.messages.IllegalCommandSyntaxException;
import net.sf.odinms.client.messages.MessageCallback;
import net.sf.odinms.net.MaplePacket;
import net.sf.odinms.net.channel.ChannelServer;
import net.sf.odinms.server.MapleInventoryManipulator;
import net.sf.odinms.server.MapleItemInformationProvider;
import net.sf.odinms.server.TimerManager;
import net.sf.odinms.server.life.MapleLifeFactory;
import net.sf.odinms.server.life.MapleNPC;
import net.sf.odinms.server.maps.MapleMapObject;
import net.sf.odinms.server.maps.MapleMapObjectType;
import net.sf.odinms.tools.DateUtil;
import net.sf.odinms.tools.HexTool;
import net.sf.odinms.tools.MaplePacketCreator;
import net.sf.odinms.tools.data.output.MaplePacketLittleEndianWriter;

public class CharCommands implements Command {

    @SuppressWarnings("static-access")
    @Override
    public void execute(MapleClient c, MessageCallback mc, String[] splitted) throws Exception, IllegalCommandSyntaxException {
        MapleCharacter player = c.getPlayer();
        if (splitted[0].equals("!maxstats")) {
            player.setMaxHp(99999);
            player.setMaxMp(99999);
            player.setStr(Short.MAX_VALUE);
            player.setDex(Short.MAX_VALUE);
            player.setInt(Short.MAX_VALUE);
            player.setLuk(Short.MAX_VALUE);
            player.updateSingleStat(MapleStat.MAXHP, 99999);
            player.updateSingleStat(MapleStat.MAXMP, 99999);
            player.updateSingleStat(MapleStat.STR, Short.MAX_VALUE);
            player.updateSingleStat(MapleStat.DEX, Short.MAX_VALUE);
            player.updateSingleStat(MapleStat.INT, Short.MAX_VALUE);
            player.updateSingleStat(MapleStat.LUK, Short.MAX_VALUE);
        } else if (splitted[0].equals("!minstats")) {
            player.setMaxHp(50);
            player.setMaxMp(5);
            player.setStr(4);
            player.setDex(4);
            player.setInt(4);
            player.setLuk(4);
            player.updateSingleStat(MapleStat.MAXHP, 50);
            player.updateSingleStat(MapleStat.MAXMP, 5);
            player.updateSingleStat(MapleStat.STR, 4);
            player.updateSingleStat(MapleStat.DEX, 4);
            player.updateSingleStat(MapleStat.INT, 4);
            player.updateSingleStat(MapleStat.LUK, 4);
        } else if (splitted[0].equals("!test")) {
            player.setHp(9999);
            player.setMp(9999);
            player.setMaxHp(9999);
            player.setMaxMp(9999);
            player.setStr(9999);
            player.setDex(9999);
            player.setInt(9999);
            player.setLuk(9999);
            player.updateSingleStat(MapleStat.HP, 9999);
            player.updateSingleStat(MapleStat.MP, 9999);
            player.updateSingleStat(MapleStat.MAXHP, 9999);
            player.updateSingleStat(MapleStat.MAXMP, 9999);
            player.updateSingleStat(MapleStat.STR, 9999);
            player.updateSingleStat(MapleStat.DEX, 9999);
            player.updateSingleStat(MapleStat.INT, 9999);
            player.updateSingleStat(MapleStat.LUK, 9999);
            int[] a = {1302000,1312000,1322000,1332000,1342000,1372000,1382000,
            1402000,1412000,1422000,1432000,1442000,1452000,1462000,1472000,1482000,1492000
            };
            for (int b : a) {
                MapleInventoryManipulator.addById(c, b, (short)1, "");
            }
            /*
            int a = Integer.parseInt(splitted[1]);
            MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            if(a == 1)
                ii.setCrystalInSql(); //结晶
            else if (a == 2) 
                ii.setMakeItemInfoInSql(); //锻造装备
            else
                ii.setCashShopInfoInSql();//商城
            */
        } else if (splitted[0].equals("!满技能")) {
            c.getPlayer().maxAllSkills();
        } else if (splitted[0].equals("!添加商城")) {
            MapleItemInformationProvider.getInstance().setCashShopInfoInSql();
        } else if (splitted[0].equals("!潜能")) {
            MapleItemInformationProvider.getInstance().setPotentialInSql();
            //int a = Integer.parseInt(splitted[1]);
            //MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            //a  = ii.getCrystalId(a);
            //c.getSession().write(MaplePacketCreator.DragonBall1(a, true));
            //c.getPlayer().getClient().getSession().write(MaplePacketCreator.骰子(a));
            //ii.setPotentialInSql();
            //ScriptEngineManager mgr = new ScriptEngineManager();
            //ScriptEngine engine = mgr.getEngineByExtension("js");
            // script u d 处理
            //String script = "u(6.1 * 2) + 5";
            //script.replace("u", "Math.floor");
            //script = script.replace("u", "Math.ceil");
            //System.out.println("替换式："+script);
            //String result1 = engine.eval(script).toString();
            //String result2 = result1.substring(0, result1.length() - 2);
            //System.out.println("结果输出："+result2);
            //mc.dropMessage("好了");
        } else if (splitted[0].equals("!test3")) {
            /*
             * schedule(delay)
             * 执行顺序 1 - 3 隔10秒执行2
            System.out.println("1");
            TimerManager tMan = TimerManager.getInstance();
            //tMan.start();
            tMan.schedule(new Runnable() {
                public void run() {
                //执行的地方
                    System.out.println("2");
                }
            }, 10000);
            System.out.println("3");
            */
            
            
            /*
             * register(repeatTime)
             * 执行顺序 1 - 3 - 2 (立刻执行) 然后每隔10秒执行2
            System.out.println("1");
            TimerManager tMan = TimerManager.getInstance();
            tMan.start();
            tMan.register(new Runnable() {
                public void run() {
                //执行的地方
                    System.out.println("2");
                }
            }, 10000);
            System.out.println("3");
             */
            
            /*
             * register(repeatTime, delay)
             * 执行顺序 1 - 3 - 2(隔了3秒才到2 而且只延时一次 delay作用只有一次) 然后每隔10秒执行2
            System.out.println("1");
            TimerManager tMan = TimerManager.getInstance();
            tMan.start();
            tMan.register(new Runnable() {
                public void run() {
                //执行的地方
                    System.out.println("2");
                }
            }, 10000, 3000);
            System.out.println("3");
             */
        } else if (splitted[0].equals("!飓风")) {
            int a = Integer.parseInt(splitted[1]);
            c.getSession().write(MaplePacketCreator.shenlong(a));
        } else if (splitted[0].equals("!maxhp")) {
            int stat = Integer.parseInt(splitted[1]);
            player.setMaxHp(stat);
            player.updateSingleStat(MapleStat.MAXHP, stat);
        } else if (splitted[0].equals("!maxmp")) {
            int stat = Integer.parseInt(splitted[1]);
            player.setMaxMp(stat);
            player.updateSingleStat(MapleStat.MAXMP, stat);
        } else if (splitted[0].equals("!hp")) {
            int stat = Integer.parseInt(splitted[1]);
            player.setHp(stat);
            player.updateSingleStat(MapleStat.HP, stat);
        } else if (splitted[0].equals("!mp")) {
            int stat = Integer.parseInt(splitted[1]);
            player.setMp(stat);
            player.updateSingleStat(MapleStat.MP, stat);
        } else if (splitted[0].equals("!str")) {
            int stat = Integer.parseInt(splitted[1]);
            player.setStr(stat);
            player.updateSingleStat(MapleStat.STR, stat);
        } else if (splitted[0].equals("!dex")) {
            int stat = Integer.parseInt(splitted[1]);
            player.setDex(stat);
            player.updateSingleStat(MapleStat.DEX, stat);
        } else if (splitted[0].equals("!int")) {
            int stat = Integer.parseInt(splitted[1]);
            player.setInt(stat);
            player.updateSingleStat(MapleStat.INT, stat);
        } else if (splitted[0].equals("!luk")) {
            int stat = Integer.parseInt(splitted[1]);
            player.setLuk(stat);
            player.updateSingleStat(MapleStat.LUK, stat);
        } else if (splitted[0].equals("!skill")) {
            ISkill skill = SkillFactory.getSkill(Integer.parseInt(splitted[1]));
            int level = getOptionalIntArg(splitted, 2, 1);
            int masterlevel = getOptionalIntArg(splitted, 3, 1);
            if (level > skill.getMaxLevel()) {
                level = skill.getMaxLevel();
            }
            if (masterlevel > skill.getMaxLevel() && skill.isFourthJob()) {
                masterlevel = skill.getMaxLevel();
            } else {
                masterlevel = 0;
            }
            player.changeSkillLevel(skill, level, masterlevel);
        } else if (splitted[0].equals("!sp")) {
            int sp = Integer.parseInt(splitted[1]);
            if (sp + player.getRemainingSp() > Short.MAX_VALUE) {
                sp = Short.MAX_VALUE;
            }
            player.setRemainingSp(sp);
            player.updateSingleStat(MapleStat.AVAILABLESP, player.getRemainingSp());
        } else if (splitted[0].equals("!ap")) {
            int ap = Integer.parseInt(splitted[1]);
            if (ap + player.getRemainingAp() > Short.MAX_VALUE) {
                ap = Short.MAX_VALUE;
            }
            player.setRemainingAp(ap);
            player.updateSingleStat(MapleStat.AVAILABLEAP, player.getRemainingAp());
        } else if (splitted[0].equals("!job")) {
            int jobId = Integer.parseInt(splitted[1]);

            if(jobId==0) {
                player.changeJob(MapleJob.BEGINNER);//新手
            }else if(jobId==100) {
                player.changeJob(MapleJob.WARRIOR);
            }else if(jobId==110) {
                player.changeJob(MapleJob.FIGHTER);
            }else if(jobId==111) {
                player.changeJob(MapleJob.CRUSADER);
            }else if(jobId==112) {
                player.changeJob(MapleJob.HERO);
            }else if(jobId==120) {
                player.changeJob(MapleJob.PAGE);
            }else if(jobId==121) {
                player.changeJob(MapleJob.WHITEKNIGHT);
            }else if(jobId==122) {
                player.changeJob(MapleJob.PALADIN);
            }else if(jobId==130) {
                player.changeJob(MapleJob.SPEARMAN);
            }else if(jobId==131) {
                player.changeJob(MapleJob.DRAGONKNIGHT);
            }else if(jobId==132) {
                player.changeJob(MapleJob.DARKKNIGHT);
            }else if(jobId==200) {
                player.changeJob(MapleJob.MAGICIAN);
            }else if(jobId==210) {
                player.changeJob(MapleJob.FP_WIZARD);
            }else if(jobId==211) {
                player.changeJob(MapleJob.FP_MAGE);
            }else if(jobId==212) {
                player.changeJob(MapleJob.FP_ARCHMAGE);
            }else if(jobId==220) {
                player.changeJob(MapleJob.IL_WIZARD);
            }else if(jobId==221) {
                player.changeJob(MapleJob.IL_MAGE);
            }else if(jobId==222) {
                player.changeJob(MapleJob.IL_ARCHMAGE);
            }else if(jobId==230) {
                player.changeJob(MapleJob.CLERIC);
            }else if(jobId==231) {
                player.changeJob(MapleJob.PRIEST);
            }else if(jobId==232) {
                player.changeJob(MapleJob.BISHOP);
            }else if(jobId==300) {
                player.changeJob(MapleJob.BOWMAN);
            }else if(jobId==310) {
                 player.changeJob(MapleJob.HUNTER);
            }else if(jobId==311) {
                 player.changeJob(MapleJob.RANGER);
            }else if(jobId==312) {
                 player.changeJob(MapleJob.BOWMASTER);
            }else if(jobId==320) {
                 player.changeJob(MapleJob.CROSSBOWMAN);
            }else if(jobId==321) {
                 player.changeJob(MapleJob.SNIPER);
            }else if(jobId==322) {
                player.changeJob(MapleJob.CROSSBOWMASTER);
            }else if(jobId==400) {
                player.changeJob(MapleJob.THIEF);
            }else if(jobId==410) {
                player.changeJob(MapleJob.ASSASSIN);
            }else if(jobId==411) {
                player.changeJob(MapleJob.HERMIT);
            }else if(jobId==412) {
                player.changeJob(MapleJob.NIGHTLORD);
            }else if(jobId==420) {
                player.changeJob(MapleJob.BANDIT);
            }else if(jobId==421) {
                player.changeJob(MapleJob.CHIEFBANDIT);
            }else if(jobId==422) {
                player.changeJob(MapleJob.SHADOWER);
            }else if(jobId==500) {
                player.changeJob(MapleJob.PIRATE);
            }else if(jobId==510) {
                player.changeJob(MapleJob.BRAWLER);
            }else if(jobId==511) {
                player.changeJob(MapleJob.MARAUDER);
            }else if(jobId==512) {
                player.changeJob(MapleJob.BUCCANEER);
            }else if(jobId==520) {
                player.changeJob(MapleJob.GUNSLINGER);
            }else if(jobId==521) {
                player.changeJob(MapleJob.OUTLAW);
            }else if(jobId==522) {
                player.changeJob(MapleJob.CORSAIR);
            }else if(jobId==1000) {
                player.changeJob(MapleJob.KNIGHT);
            }else if(jobId==1100) {
                player.changeJob(MapleJob.GHOST_KNIGHT);
            }else if(jobId==1110) {
                player.changeJob(MapleJob.GHOST_KNIGHT_2);
            }else if(jobId==1111) {
                player.changeJob(MapleJob.GHOST_KNIGHT_3);
            }else if(jobId==1200) {
                player.changeJob(MapleJob.FIRE_KNIGHT);
            }else if(jobId==1210) {
                player.changeJob(MapleJob.FIRE_KNIGHT_2);
            }else if(jobId==1211) {
                player.changeJob(MapleJob.FIRE_KNIGHT_3);
            }else if(jobId==1300) {
                player.changeJob(MapleJob.WIND_KNIGHT);
            }else if(jobId==1310) {
                player.changeJob(MapleJob.WIND_KNIGHT_2);
            }else if(jobId==1311) {
                player.changeJob(MapleJob.WIND_KNIGHT_3);
            }else if(jobId==1400) {
                player.changeJob(MapleJob.NIGHT_KNIGHT);
            }else if(jobId==1410) {
                player.changeJob(MapleJob.NIGHT_KNIGHT_2);
            }else if(jobId==1411) {
                player.changeJob(MapleJob.NIGHT_KNIGHT_3);
            }else if(jobId==1500) {
                player.changeJob(MapleJob.THIEF_KNIGHT);
            }else if(jobId==1510) {
                player.changeJob(MapleJob.THIEF_KNIGHT_2);
            }else if(jobId==1511) {
                player.changeJob(MapleJob.THIEF_KNIGHT_3);
            }else if(jobId==2000) {
                player.changeJob(MapleJob.Aran);
            }else if(jobId==2100) {
                player.changeJob(MapleJob.Aran_1);
            }else if(jobId==2110) {
                player.changeJob(MapleJob.Aran_2);
            }else if(jobId==2111) {
                player.changeJob(MapleJob.Aran_3);
            }else if(jobId==2112) {
                player.changeJob(MapleJob.Aran_4);
            }else if(jobId==3000) {
                 player.changeJob(MapleJob.Resistance);
            }else if(jobId==3200) {
                 player.changeJob(MapleJob.Battlemage_1);
            }else if(jobId==3210) {
                 player.changeJob(MapleJob.Battlemage_2);
            }else if(jobId==3211) {
                 player.changeJob(MapleJob.Battlemage_3);
            }else if(jobId==3212) {
                 player.changeJob(MapleJob.Battlemage_4);
            }else if(jobId==3300) {
                 player.changeJob(MapleJob.wildhunter_1);
            }else if(jobId==3310) {
                 player.changeJob(MapleJob.wildhunter_2);
            }else if(jobId==3311) {
                 player.changeJob(MapleJob.wildhunter_3);
            }else if(jobId==3312) {
                 player.changeJob(MapleJob.wildhunter_4);
            }else if(jobId==3500) {
                 player.changeJob(MapleJob.mechinic_1);
            }else if(jobId==3510) {
                 player.changeJob(MapleJob.mechinic_2);
            }else if(jobId==3511) {
                 player.changeJob(MapleJob.mechinic_3);
            }else if(jobId==3512) {
                 player.changeJob(MapleJob.mechinic_4);
            }else if(jobId==430) {
                 player.changeJob(MapleJob.Dual_Blade_1);
            }else if(jobId==431) {
                 player.changeJob(MapleJob.Dual_Blade_2);
            }else if(jobId==432) {
                 player.changeJob(MapleJob.Dual_Blade_3);
            }else if(jobId==433) {
                 player.changeJob(MapleJob.Dual_Blade_4);
            }else if(jobId==434) {
                 player.changeJob(MapleJob.Dual_Blade_5);
             }else if(jobId==2001) {
                 player.changeJob(MapleJob.Evan);
             }else if(jobId==2200) {
                 player.changeJob(MapleJob.Evan_1);
             }else if(jobId==2210) {
                 player.changeJob(MapleJob.Evan_2);
             }else if(jobId==2211) {
                 player.changeJob(MapleJob.Evan_3);
             }else if(jobId==2212) {
                 player.changeJob(MapleJob.Evan_4);
             }else if(jobId==2213) {
                 player.changeJob(MapleJob.Evan_5);
             }else if(jobId==2214) {
                 player.changeJob(MapleJob.Evan_6);
             }else if(jobId==2215) {
                 player.changeJob(MapleJob.Evan_7);
             }else if(jobId==2216) {
                 player.changeJob(MapleJob.Evan_8);
             }else if(jobId==2217) {
                 player.changeJob(MapleJob.Evan_9);
             }else if(jobId==2218) {
                 player.changeJob(MapleJob.Evan_10);
             }else if(jobId==900) {
                 player.changeJob(MapleJob.GM);
             }else if(jobId==9200){
                 player.changeJob(MapleJob.采矿);
             }else if(jobId==9201){
                 player.changeJob(MapleJob.采药);
             }else if(jobId==9202){
                 player.changeJob(MapleJob.装备制作);
             }else if(jobId==9203){
                 player.changeJob(MapleJob.饰品制作);
             }else if(jobId==9204){
                 player.changeJob(MapleJob.炼金术);
             }else if(jobId==800){
                 player.changeJob(MapleJob.fuck1);
             }else if(jobId==9000){
                 player.changeJob(MapleJob.fuck2);
             }else if(jobId==9100){
                 player.changeJob(MapleJob.fuck3);
            }else{
                mc.dropMessage("你输入的职业代码有错!");
            }
        } else if (splitted[0].equals("!whereami")) {
            int currentMap = player.getMapId();
            mc.dropMessage("You are on map " + currentMap + ".");
        } else if (splitted[0].equals("!1")) {
            c.getPlayer().showDojoClock();
            c.getSession().write(MaplePacketCreator.enableActions());
        } else if (splitted[0].equals("!2")) {
            c.getSession().write(MaplePacketCreator.environmentChange("Dojang/start", 4));
            c.getSession().write(MaplePacketCreator.enableActions());
        } else if (splitted[0].equals("!3")) {
            c.getSession().write(MaplePacketCreator.environmentChange("dojang/start/stage", 3));
            c.getSession().write(MaplePacketCreator.enableActions());
        } else if (splitted[0].equals("!4")) {
            c.getSession().write(MaplePacketCreator.getEnergy(c.getPlayer().getDojoEnergy()));
            c.getSession().write(MaplePacketCreator.enableActions());
        } else if (splitted[0].equals("!5")) {
            c.getSession().write(MaplePacketCreator.sendBlockedMessage(5));
            c.getSession().write(MaplePacketCreator.enableActions());
        } else if (splitted[0].equals("!6")) {
            c.getSession().write(MaplePacketCreator.enableActions());
        } else if (splitted[0].equals("!关门")) {
            player.getMap().clearDrops(player, true);
        } else if (splitted[0].equals("!8")) {
            c.getSession().write(MaplePacketCreator.Combo_Effect(8));
            c.getSession().write(MaplePacketCreator.enableActions());
        } else if (splitted[0].equals("!meso")) {
            if (Integer.MAX_VALUE - (player.getMeso() + Integer.parseInt(splitted[1])) >= 0) {
                player.gainMeso(Integer.parseInt(splitted[1]), true);
            } else {
                player.gainMeso(Integer.MAX_VALUE - player.getMeso(), true);
            }
        } else if (splitted[0].equals("!levelup")) {
            if (player.getLevel() < 200) {
                player.levelUp();
                player.setExp(0);
            } else {
                mc.dropMessage("You are already level 200.");
            }
        } else if (splitted[0].equals("!level")) {
            int quantity = Integer.parseInt(splitted[1]);
            c.getPlayer().setLevel(quantity);
            c.getPlayer().levelUp();
            int newexp = c.getPlayer().getExp();
            if (newexp < 0) {
                c.getPlayer().gainExp(-newexp, false, false);
            }
        } else if (splitted[0].equals("!item")) {
            MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            short quantity = (short) getOptionalIntArg(splitted, 2, 1);
            if (Integer.parseInt(splitted[1]) >= 5000000 && Integer.parseInt(splitted[1]) <= 5000100) {
                if (quantity > 1) {
                    quantity = 1;
                }
                int petId = MaplePet.createPet(Integer.parseInt(splitted[1]));
                MapleInventoryManipulator.addById(c, Integer.parseInt(splitted[1]), quantity, player.getName() + "used !item with quantity " + quantity, player.getName(), petId);
                return;
            } else if (ii.isRechargable(Integer.parseInt(splitted[1]))) {
                quantity = ii.getSlotMax(c, Integer.parseInt(splitted[1]));
                MapleInventoryManipulator.addById(c, Integer.parseInt(splitted[1]), quantity, "Rechargable item created.", player.getName(), -1);
                return;
            }
            MapleInventoryManipulator.addById(c, Integer.parseInt(splitted[1]), quantity, player.getName() + "used !item with quantity " + quantity, player.getName(), -1);
        } else if (splitted[0].equals("!nonameitem")) {
            MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            short quantity = (short) getOptionalIntArg(splitted, 2, 1);
            if (Integer.parseInt(splitted[1]) >= 5000000 && Integer.parseInt(splitted[1]) <= 5000100) {
                if (quantity > 1) {
                    quantity = 1;
                }
                int petId = MaplePet.createPet(Integer.parseInt(splitted[1]));
                return;
            } else if (ii.isRechargable(Integer.parseInt(splitted[1]))) {
                quantity = ii.getSlotMax(c, Integer.parseInt(splitted[1]));
                return;
            }
            MapleInventoryManipulator.addById(c, Integer.parseInt(splitted[1]), quantity, player.getName() + "used !nonameitem with quantity " + quantity);
        } else if (splitted[0].equals("!警告")) {
            ChannelServer cserv = c.getChannelServer();
            cserv.getPlayerStorage().getCharacterByName(splitted[1]).gainWarning(true, 1);
        } else if (splitted[0].equals("!drop")) {
            MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            int itemId = Integer.parseInt(splitted[1]);
            short quantity = (short) getOptionalIntArg(splitted, 2, 1);
            IItem toDrop;
            if (ii.getInventoryType(itemId) == MapleInventoryType.EQUIP) {
                toDrop = ii.randomizeStats((Equip) ii.getEquipById(itemId));
            } else {
                toDrop = new Item(itemId, (byte) 0, quantity);
            }
            toDrop.log("Created by " + player.getName() + " using !drop. Quantity: " + quantity, false);
            toDrop.setOwner(player.getName());
            player.getMap().spawnItemDrop(player, player, toDrop, player.getPosition(), true, true);
        } else if (splitted[0].equals("!nonamedrop")) {
            MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
            int itemId = Integer.parseInt(splitted[1]);
            short quantity = (short) getOptionalIntArg(splitted, 2, 1);
            IItem toDrop;
            if (ii.getInventoryType(itemId) == MapleInventoryType.EQUIP) {
                toDrop = ii.randomizeStats((Equip) ii.getEquipById(itemId));
            } else {
                toDrop = new Item(itemId, (byte) 0, quantity);
            }
            player.getMap().spawnItemDrop(player, player, toDrop, player.getPosition(), true, true);
        } else if (splitted[0].equals("!等级")) {
            int quantity = Integer.parseInt(splitted[1]);
            c.getPlayer().setLevel(quantity);
            c.getPlayer().levelUp();
            int newexp = c.getPlayer().getExp();
            if (newexp < 0) {
                c.getPlayer().gainExp(-newexp, false, false);
            }
        } else if (splitted[0].equals("!最大等级")) {
            while (player.getLevel() < 200) {
                player.levelUp();
            }
            player.gainExp(-player.getExp(), false, false);
        } else if (splitted[0].equals("!ring")) {
            /*
            int itemId = Integer.parseInt(splitted[1]);
            String partnerName = splitted[2];
            String message = splitted[3];
            int ret = MapleRing.createRing(itemId, player, player.getClient().getChannelServer().getPlayerStorage().getCharacterByName(partnerName), message);
            if (ret == -1) {
            mc.dropMessage("Error - Make sure the person you are attempting to create a ring with is online.");
            }
             */
        } else if (splitted[0].equals("!ariantpq")) {
            if (splitted.length < 2) {
                player.getMap().AriantPQStart();
            } else {
                c.getSession().write(MaplePacketCreator.updateAriantPQRanking(splitted[1], 5, false));
            }
        } else if (splitted[0].equals("!dh")) {
            c.getPlayer().startCygnusIntro();
        } else if (splitted[0].equals("!dh3")) {
            c.getPlayer().startCygnusIntro_3();
        } else if (splitted[0].equals("!playernpc")) {
            c.getPlayer().getPlayerNPC().createPNE();
            c.getPlayer().getPlayerNPC().createPlayerNPC(c.getPlayer(), c.getPlayer().getMapId());
        } else if (splitted[0].equals("!position")) {
            mc.dropMessage("Your current co-ordinates are: " + c.getPlayer().getPosition().x + " x and " + c.getPlayer().getPosition().y + " y.");
        } else if (splitted[0].equals("!clearinvent")) {
            if (splitted.length < 2) {
                mc.dropMessage("Please specify which tab to clear. If you want to clear all, use '!clearinvent all'.");
            } else {
                String type = splitted[1];
                boolean pass = false;
                if (type.equals("equip") || type.equals("all")) {
                    if (!pass) {
                        pass = true;
                    }
                    for (int i = 0; i < 101; i++) {
                        IItem tempItem = c.getPlayer().getInventory(MapleInventoryType.EQUIP).getItem((byte) i);
                        if (tempItem == null) {
                            continue;
                        }
                        MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.EQUIP, (byte) i, tempItem.getQuantity(), false, true);
                    }
                }
                if (type.equals("use") || type.equals("all")) {
                    if (!pass) {
                        pass = true;
                    }
                    for (int i = 0; i < 101; i++) {
                        IItem tempItem = c.getPlayer().getInventory(MapleInventoryType.USE).getItem((byte) i);
                        if (tempItem == null) {
                            continue;
                        }
                        MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.USE, (byte) i, tempItem.getQuantity(), false, true);
                    }
                }
                if (type.equals("etc") || type.equals("all")) {
                    if (!pass) {
                        pass = true;
                    }
                    for (int i = 0; i < 101; i++) {
                        IItem tempItem = c.getPlayer().getInventory(MapleInventoryType.ETC).getItem((byte) i);
                        if (tempItem == null) {
                            continue;
                        }
                        MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.ETC, (byte) i, tempItem.getQuantity(), false, true);
                    }
                }
                if (type.equals("etc") || type.equals("all")) {
                    if (!pass) {
                        pass = true;
                    }
                    for (int i = 0; i < 101; i++) {
                        IItem tempItem = c.getPlayer().getInventory(MapleInventoryType.SETUP).getItem((byte) i);
                        if (tempItem == null) {
                            continue;
                        }
                        MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.SETUP, (byte) i, tempItem.getQuantity(), false, true);
                    }
                }
                if (type.equals("cash") || type.equals("all")) {
                    if (!pass) {
                        pass = true;
                    }
                    for (int i = 0; i < 101; i++) {
                        IItem tempItem = c.getPlayer().getInventory(MapleInventoryType.CASH).getItem((byte) i);
                        if (tempItem == null || tempItem.getUniqueId() != 0) {
                            continue;
                        }
                        MapleInventoryManipulator.removeFromSlot(c, MapleInventoryType.CASH, (byte) i, tempItem.getQuantity(), false, true);
                    }
                }
                if (!pass) {
                    mc.dropMessage("!clearinvent " + type + " does not exist!");
                } else {
                    mc.dropMessage("Your inventory has been cleared!");
                }
            }
        } else if (splitted[0].equals("!eventlevel")) {
            int minlevel = Integer.parseInt(splitted[1]);
            int maxlevel = Integer.parseInt(splitted[2]);
            int map = Integer.parseInt(splitted[3]);
            int minutes = getOptionalIntArg(splitted, 4, 5);
            if (splitted.length < 4) {
                mc.dropMessage("Syntax Error: !eventlevel <minlevel> <maxlevel> <mapid> <minutes>");
                return;
            }
            c.getChannelServer().startEvent(minlevel, maxlevel, map);
            final MapleNPC npc = MapleLifeFactory.getNPC(9201093);
            npc.setPosition(c.getPlayer().getPosition());
            npc.setCy(c.getPlayer().getPosition().y);
            npc.setRx0(c.getPlayer().getPosition().x + 50);
            npc.setRx1(c.getPlayer().getPosition().x - 50);
            npc.setFh(c.getPlayer().getMap().getFootholds().findBelow(c.getPlayer().getPosition()).getId());
            npc.setCustom(true);
            c.getPlayer().getMap().addMapObject(npc);
            c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.spawnNPC(npc));
            MaplePacket msgpacket = MaplePacketCreator.serverNotice(6, "The NPC " + npc.getName() + " will be in " + c.getPlayer().getMap().getMapName() + " for " + minutes + " minutes(s). Please talk to it to be warped to the Event (Must be in between level " + minlevel + " and " + maxlevel + ")");
            ChannelServer.getInstance(c.getChannel()).getWorldInterface().broadcastMessage(c.getPlayer().getName(), msgpacket.getBytes());
            final MapleCharacter playerr = c.getPlayer();
            TimerManager.getInstance().schedule(new Runnable() {

                @Override
                public void run() {
                    List<MapleMapObject> npcs = playerr.getMap().getMapObjectsInRange(playerr.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapleMapObjectType.NPC));
                    for (MapleMapObject npcmo : npcs) {
                        MapleNPC fnpc = (MapleNPC) npcmo;
                        if (fnpc.isCustom() && fnpc.getId() == npc.getId()) {
                            playerr.getMap().removeMapObject(fnpc.getObjectId());
                        }
                    }
                }
            }, minutes * 60 * 1000);
        }
        
    }

    @Override
    public CommandDefinition[] getDefinition() {
        return new CommandDefinition[]{
            new CommandDefinition("飓风", "", "", 0),
            new CommandDefinition("test", "", "", 0),
            new CommandDefinition("test2", "", "", 0),
            new CommandDefinition("test3", "", "", 0),
            new CommandDefinition("添加商城", "", "", 0),
            new CommandDefinition("团队治疗", "", "", 0),
            new CommandDefinition("1", "", "", 3),
            new CommandDefinition("2", "", "", 3),
            new CommandDefinition("3", "", "", 3),
            new CommandDefinition("4", "", "", 3),
            new CommandDefinition("5", "", "", 3),
            new CommandDefinition("6", "", "", 3),
            new CommandDefinition("关门", "", "", 3),
            new CommandDefinition("8", "", "", 3),
            new CommandDefinition("maxstats", "", "", 50),
            new CommandDefinition("minstats", "", "", 50),
            new CommandDefinition("maxskills", "", "", 50),
            new CommandDefinition("maxhp", "", "", 50),
            new CommandDefinition("maxmp", "", "", 50),
            new CommandDefinition("hp", "", "", 50),
            new CommandDefinition("mp", "", "", 50),
            new CommandDefinition("str", "", "", 50),
            new CommandDefinition("dex", "", "", 50),
            new CommandDefinition("int", "", "", 50),
            new CommandDefinition("luk", "", "", 50),
            new CommandDefinition("skill", "", "", 4),
            new CommandDefinition("sp", "", "", 50),
            new CommandDefinition("ap", "", "", 50),
            new CommandDefinition("godmode", "", "", 50),
            new CommandDefinition("job", "", "", 50),
            new CommandDefinition("gob", "", "", 50),
            new CommandDefinition("whereami", "", "", 1),
            new CommandDefinition("警告", "", "", 1),
            new CommandDefinition("shop", "", "", 50),
            new CommandDefinition("meso", "", "", 50),
            new CommandDefinition("levelup", "", "", 50),
            new CommandDefinition("item", "", "", 50),
            new CommandDefinition("nonameitem", "", "", 50),
            new CommandDefinition("drop", "", "", 50),
            new CommandDefinition("nonamedrop", "", "", 50),
            new CommandDefinition("level", "", "", 50),
            new CommandDefinition("maxlevel", "", "", 50),
            new CommandDefinition("ring", "", "", 50),
            new CommandDefinition("ariantpq", "", "", 50),
            new CommandDefinition("dh", "", "", 50),
            new CommandDefinition("dh3", "", "", 50),
            new CommandDefinition("scoreboard", "", "", 50),
            new CommandDefinition("playernpc", "", "", 50),
            new CommandDefinition("charinfo", "charname", "Shows info about the character with the given name", 1),
            new CommandDefinition("selfinfo", "charname", "Shows info about your own character", 50),
            new CommandDefinition("position", "", "Shows your character's coordinates", 50),
            new CommandDefinition("clearinvent", "<all, equip, use, etc, setup, cash>", "Clears the desired inventory", 50),
            new CommandDefinition("eventlevel", "<minlevel> <maxlevel> <mapid> <minutes>", "Spawns NPC to warp to an event", 50)
        };
    }
}